package Messages;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import ocsf.server.ConnectionToClient;
import server.SQLConnection;
/**
 * this class implements the update book details in db
 * @author Ron Shenkerman
 * @author Gabi Revah
 * @author Aviad Almog
 * @author Ivan Onyshchenko
 */
public class MessageUpdateBookDetails {

	private ConnectionToClient client;
	/**
	 * constractor of this class 
	 * @param client
	 */
	public MessageUpdateBookDetails(ConnectionToClient client) {
		// TODO Auto-generated constructor stub
		super();
		this.client=client;
		
	}
	/**
	 * updating book details in the DB 
	 * @param bid
	 */
public void UpdateBookDetails(String bid){
		
		try 
		{

			System.out.println("Getting book detail for viewing");
			Statement stmt;
			SQLConnection conn = new  SQLConnection();
			stmt = conn.getConnection().createStatement();
			ResultSet rs= stmt.executeQuery("SELECT * FROM db1.books WHERE id='"+bid+"';");
				try {
				
						if (rs.next())
							{

								ArrayList<String> ViewArr=new ArrayList<String>();
								ViewArr.add("UpdatebookSearch");
								ViewArr.add(rs.getString(1));
								ViewArr.add(rs.getString(2));
								ViewArr.add(rs.getString(3));
								ViewArr.add(rs.getString(4));
								ViewArr.add(rs.getString(5));
								ViewArr.add(rs.getString(6));
								ViewArr.add(rs.getString(7));
							//	ViewArr.add(rs.getString(8));
								ViewArr.add(rs.getString(9));
								ViewArr.add(rs.getString(10));


								
						        
								client.sendToClient(ViewArr);
								
							}
						else if (!(rs.next()))
							{
								
								client.sendToClient("UpdateBookDetailsFaild");
							}
  
					}
						catch (SQLException e)
								{	
								e.printStackTrace();
								}
		}
  
		catch (Exception ex )
		{
	  ex.printStackTrace();
		}


}
	
	
	

}
